/*
Copyright (C) 2021-2025 Casa Xu (also Zhiyan Xu) from HIT

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
/*
 * LOS_TMTC.h
 *
 *  Created on: 2022
 *      Author: 64435
 */

#ifndef PERIPHERAL_LAYER_INC_LOS_TMTC_H_
#define PERIPHERAL_LAYER_INC_LOS_TMTC_H_

#include "LOS_FlightProcedure.h"
#include "LOS_State.h"



typedef struct LOS_TMTC_t
{
    /* 健康管理状态量 */
    uint8_t VAL;                 //数据有效性标志，0：有效， 其他值：无效
    uint8_t CMD;                 //开关机指令状态,发送开机指令后置1，发送关机指令后置0
    uint8_t PWR;                 //电源状态，读取电源遥测，通电为1，断电为0
    uint8_t MSG;                 //通信状态，通信正常为0，通信异常为其他值
    uint8_t SWNUM;
    uint8_t RBCNT;               //复位次数
    uint8_t NFR;                 //Need For Reset 需要复位标志位，1为需要复位，0为不需要
    uint8_t REC;                //CAN识别标志位,0:未识别  1：识别
    uint8_t HL_TXF;              //HL_前缀表示健康管理相关变量。遥测请求发送完成标志,发送一次后该量置1，接收到回应后置0(TX FINISHED)
    uint8_t HL_WCNT;             //等待接收计数器。该计数器在操作系统的一个线程中累加，当HL_TXF为1时该值+1，HL_TXF为0时该值清0，当累加到一定值时系统会判断通信异常，并将MSG置1
    /* 测控状态量 */
    uint8_t FTP_FileNum;        //当前发送文件序号
    uint32_t FTP_FileSize;      //当前发送文件大小
}LOS_TMTC_t;

extern LOS_TMTC_t STA_TMTC;

//extern uint8_t TM_PACK0[208];
extern uint8_t tempf;
extern uint8_t TC_CMD_BUF[400]; 
extern uint8_t TC_FCNT;

extern uint8_t TMPACK_TMTCBasic[130];

void LOS_TMTC_TMSend(uint8_t* tmmsg, uint16_t datalen);
void LOS_TMTC_PicSend(uint8_t* pic);
void LOS_CAN_TMTCCallBack(LOS_CANMSG_t* can_re);

void LOS_TMTC_CMD(uint8_t* cmd);

void LOS_TMTC_Reset();
void LOS_TMTC_GetStatus();
void LOS_TMTC_SetFile(uint8_t filenum);
void LOS_TMTC_DeleteFile(uint8_t filenum);
void LOS_TMTC_SetTargetnID(uint8_t nID);
void LOS_TMTC_ReadBlock(uint32_t offset, uint32_t length);
void LOS_TMTC_FTPStart();
void LOS_TMTC_FTPStop();
void LOS_TMTC_SetSeed(uint8_t* seed);
void LOS_TMTC_SetPackCNT(uint16_t cnt);
void LOS_TMTC_SetFTPInv(uint8_t inv);
void LOS_TMTC_ArgDownViaRF();
void LOS_TMTC_TM30SON();
void LOS_TMTC_TM30SOFF();
void LOS_TMTC_FileDownViaRF(uint32_t offset, uint32_t length);

void LOS_UHF1_PWROn();
void LOS_UHF1_PWROff();
void LOS_VHF1_PWROn();
void LOS_VHF1_PWROff();
void LOS_UHF2_PWROn();
void LOS_UHF2_PWROff();
void LOS_VHF2_PWROn();
void LOS_VHF2_PWROff();

#endif /* PERIPHERAL_LAYER_INC_LOS_TMTC_H_ */
